<cfoutput>
<!---<cfset parmlist=URLEncodedFormat('un~demo123|pswd~demo123|method~processtranx|tranxtype~sale|terms~Y|swipe~#form.cc#|amount~#form.amount#|baddress~1234 Main|bzip~99201|invoice~#session.ReceiptNum#|')>--->

<!---card swiped  -- - - -- - -  - ---->
<cfset parmlist=URLEncodedFormat('un~demo123|pswd~demo123|method~processtranx|tranxtype~Sale|terms~Y|swipe~#form.cc#|amount~#form.amount#|invoice~#session.ReceiptNum#|TEST~Y')>

<!---card keyed - - - - - - - - - --->

<!---<cfset parmlist=URLEncodedFormat('un~demo123|pswd~demo123|method~processtranx|tranxtype~sale|terms~Y|CC~4012881888818888|expmnth~12|expyr~12|amount~1.12|baddress~1234 Main|bzip~99201|invoice~123456abcd|')>--->


<cfhttp url="https://PayTrace.com/API/default.pay?parmList=#parmlist#"></cfhttp>

  
  <cfset checkcust = "#cfhttp.filecontent#">

 <cfset checkone = listGetAt(checkcust, 1, "~")>
  <cfset checktwo = listGetAt(checkcust, 2, "~")>
 <cfset checkthree = listGetAt(checktwo, 1,".")>
  <cfset checkfour = listGetAt(checktwo, 2,".")>


  
  
  
  
  
<cfset today = dateformat(now(), "mm/dd/yyyy")>
<cfset mytime = timeformat(now(), "hh:mm:ss")>

<cfset checkcard = "#form.cc#">

<cfset cc_lastName =  listgetAt(checkcard,2,"/^;")>
<cfset cc_firstName =  listgetAt(checkcard,3,"/^;")>


<cfset par_cc_num =  listgetAt(checkcard,1,"%^;")>

<cfset cc =  right(par_cc_num,16)>

<cfset par_date =  listgetAt(checkcard,3,"^?;")>

<cfset cc_date =  left(par_date,4)>

<cfset cc_year =  left(par_date,2)>
<cfset cc_month =  right(cc_date,2)>


<cfset lastfour =  right(par_cc_num,4)>

<CFQUERY NAME="getitemssum" DATASOURCE="#dsn#">
select sum(Price) as total
from tbltransactions
where ReceiptNum = #session.ReceiptNum#
</CFQUERY>


<cfset mychange = #form.amount# - #getitemssum.total#>

<cfset myblance = #mychange#>








<CFQUERY NAME="getcodes" DATASOURCE="#Datasource#">
select *
from tblresponsecodes
where Code = #checkthree#
</CFQUERY>

<cfif #checkthree# is 101 or #checkthree# is 104>

<cfset session.response = "#checkthree# #checkfour#">

<CFQUERY NAME="getorders" DATASOURCE="#dsn#">
select *
from tblorders
where ReceiptNum = #session.ReceiptNum#
</CFQUERY>

<cfquery datasource="#dsn#">
update tblorders
set Amount = #amount#,
LastFour = #lastfour#,
FirstName = '#cc_firstName#',
LastName = '#cc_lastName#',
Paytype = 'Credit Card',
Credit = #amount#,
TransType = 'SALE'
where ReceiptNum = #session.ReceiptNum# 
</cfquery>

<CFQUERY DATASOURCE="#dsn#">
INSERT INTO tblpayments (Amount, ReceiptNum, TransDate, ReportTime, ReportDate, PaymentType, Change, username, amountpaid, Balance, TransType, Credit, PIN)
VALUES (
#Amount#,
#session.ReceiptNum#,
<cfqueryparam cfsqltype="cf_sql_timestamp" value="#today#">,
'#mytime#',
'#today#',
'Credit Card',
0,
'#session.username#',
#Amount#,
<cfif #myblance# gte 1>#myblance#<cfelse>0</cfif>,
'SALE',
#Amount#,
<CFIF #getorders.DODAAC# EQ "">NULL<cfelse>#getorders.DODAAC#</CFIF>
 
)
</CFQUERY>




<cflocation url="../forms/credit.cfm?response=#checkthree# #checkfour#&code=#checkthree#">
<cfelse>
<cflocation url="../forms/credit.cfm?response=#checkthree# #checkfour#&Amount=#form.amount#&code=#checkthree#">
</cfif>
  

</cfoutput>
